import instance from "./instance"
import { IResponse } from "./modules"

/***
 * @func get请求
 */

export const ajaxGet = <T>(url: string, params = {}): Promise<IResponse<T>> => {
  return instance({
    method: 'get',
    url,
    params
  })
}

/**
 * @func post请求
 * @description  用于普通表单
 */

export const ajaxPost = <T>(url: string, data: any = {}): Promise<IResponse<T>> => {
  const config = {
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  }
  return instance.post(url, data, config)
}

/**
 * @func post请求
 * @desc 用于大文件上传
 */

export const ajaxUpload = <T>(url: string, data: any = {}): Promise<IResponse<T>> => {
  const config = {
    headers: {'Content-Type': 'multipart/form-data'}
  }
  return instance.post(url, data, config)
}

/**
 * @func put请求
 */

export const ajaxPut = <T>(url: string, data: any = {}): Promise<IResponse<T>> => {
  return instance.put(url, data)
}

/**
 * @func delete请求
 */

export const ajaxDel = <T>(url: string, data = {}): Promise<IResponse<T>> => {
  return instance.delete(url, data)
}